//
// Created by 28785 on 25-7-31.

#ifndef BUILDER_H
#define BUILDER_H
#include <iostream>
#include <memory>
#include <ostream>
#include <string>


/**
 * @brief 产品类
 */
class Product
{
public:
    void setCpu(const std::string& strCpu ) {
        _strCpu = strCpu;
    }

    void setGpu(const std::string& strGpu ) {
        _strGpu = strGpu;
    }

    void setRam(const std::string& strRam ) {
        _strRam = strRam;
    }

    void setStorage(const std::string& strStorage ) {
        _strStorage = strStorage;
    }

    void showSpec() const {
        std::cout << "Cpu: " << _strCpu << std::endl
                  << "Ram: " << _strRam << std::endl
                  << "Storage: " << _strStorage << std::endl;
        !_strGpu.empty() ? std::cout << "Gpu: "<< _strGpu << std::endl
                        : std::cout <<  "NoGpu" << std::endl;
    }

private:
    std::string _strCpu;
    std::string _strGpu;
    std::string _strRam;
    std::string _strStorage;
};
#endif //BUILDER_H

/**
 * @brief 构建者接口
 */
class IBuilder {
public:
    virtual  ~IBuilder() = default;

    virtual void buildGpu() = 0;

    virtual void buildCpu() = 0;

    virtual void buildRam() = 0;

    virtual void buildStorage() = 0;

    virtual Product getResult() = 0;
};

/**
 * @brief 游戏本生产者
 */
class GameComputer : public IBuilder{
public:
    GameComputer() {
        _pProduct = std::make_unique<Product>();
    }

    void buildCpu() override{
        _pProduct->setCpu("Intel Core i9-139000K");
    }

    void buildGpu() override {
        _pProduct->setGpu("NVIDA RTX 4090");
    }

    void buildRam() override {
        _pProduct->setRam("32GB DDR% 5600MHz");
    }

    void buildStorage() override {
        _pProduct->setStorage("2TB NVMe SSD");
    }

    Product getResult() override {
        return *_pProduct;
    }

private:
    std::unique_ptr<Product> _pProduct;
};

class WorkComputer : public IBuilder {
public:
    WorkComputer() {
        _pProduct = std::make_unique<Product>();
    }

    void buildCpu() override{
        _pProduct->setCpu("Intel Core i7-139000K");
    }

    void buildGpu() override {
        _pProduct->setGpu("");
    }

    void buildRam() override {
        _pProduct->setRam("16GB DDR% 5600MHz");
    }

    void buildStorage() override {
        _pProduct->setStorage("2TB NVMe SSD");
    }

    Product getResult() override {
        return *_pProduct;
    }

private:
    std::unique_ptr<Product> _pProduct;
};

class Director {
public:
    void setBuilder(IBuilder* pBuilder) { _pBuilder = pBuilder; }

    void constructComputer() {
        _pBuilder->buildCpu();
        _pBuilder->buildGpu();
        _pBuilder->buildRam();
        _pBuilder->buildStorage();
    }

private:
    IBuilder* _pBuilder{nullptr};
};